<!--
<template>
  <el-dialog :title="title" :visible.sync="visiable" width="380px" :before-close="handleClose">
    <el-form :rules="rules" ref="formData" :model="formData" label-width="100px" label-position="right" style="width:300px;" status-icon>
      <el-form-item label="新密码:" prop="newPassword">
        <el-input v-model="formData.newPassword" type="password"></el-input>
      </el-form-item>
      <el-form-item label="确认密码:" prop="repPassword">
        <el-input v-model="formData.repPassword" type="password"></el-input>
      </el-form-item>

      <el-form-item align="center">
        <el-button type="primary" @click="submitForm('formData')" >确定</el-button>
        <el-button @click="handleClose">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import * as api from '@/api/user';
export default {
    props:{
        userId: null,          // 用户id
        visiable: {
            type :Boolean,
            default: false
        },
        title: {
            type: String,
            default: ''
        },
        remoteClose: Function
    },
    data () {
        var validatePwd = (rule, value, callback) =>{
            if (value !== this.formData.newPassword) {
                callback(new Error('两次输入密码不一致!'));
            } else {
                callback();
            }
        }

        return {
            formData: {},
            rules:{
                newPassword:[
                    {required:true, message:'请输入新密码', trigger: 'blur'},
                    {min: 6, max: 30, message: '长度为6到30个字符', trigger:'blur'}
                ],
                repPassword:[
                    {required:true, message:'请输入确认密码', trigger: 'blur'},
                    {validator: validatePwd,  trigger: 'blur'}
                ]
            }
        };
    },

    methods: {
        // // 调用父组件的方法关闭弹框
        handleClose(){
            this.$refs['formData'].resetFields();
            this.remoteClose();
        },

        // 提交表单
        submitForm(formName){
            this.$refs[formName].validate((valid) => {
            if (valid) {
              // 校验通过 提交表单数据
              this.formData.userId = this.userId;
              api.updateUserPwd(this.formData).then(response => {
                  this.handleClose();
                  if(response.code === 20000){
                      this.$message({message: '密码修改成功', type: 'success'});
                  }else{
                      this.$message({message: response.message, type: 'error'});
                  }
              })
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        },
    }
}

</script>
<style lang='scss' scoped>
</style>-->
